#include <stdio.h>
int main()
{
    int k, j, i = 0;//定义变量
    char buf[20];
    double num;
    printf("请输入一个小数:");
    scanf("%lf", &num);
    k = num;
        while (k)
        {
            buf[i++] = '0' + k % 10;//打印整数
            k = k / 10;
        }
        for (int j = 0; j < (i)/2; j++)
        {
            char ch = buf[j];
            buf[j] = buf[i-1-j];
            buf[i-1-j] = ch;
        }
    
    buf[i] = '.';//添加小数点        
    num = num - (int)num;
        
        while (num > 0.0001)//小数精度并存进数组
        {
            int result = num * 10;
            buf[++i] = '0' + result;
            num = num * 10 - result;
        }
    printf("\n将该小数转换成字符串得:");
    
    for (j = 0;j <= i;j++)//打印
    {
        printf("%c", buf[j]);
    }

    return 0;
}